package ed.hbut.supermarket1.controller;

import ed.hbut.supermarket1.dto.UpdatePasswordDto;
import ed.hbut.supermarket1.entity.Employee;
import ed.hbut.supermarket1.entity.Result;
import ed.hbut.supermarket1.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
public class SettingController {

    @Autowired
    public EmpService empService;

    @GetMapping("/api/setting/{username}")
    public Result setting(@PathVariable String username) {

        log.info("用户名{}", username);
        Employee employee= empService.getByUsername(username);
        log.info("employee {}", employee);
        return Result.success(employee);


    }

    @PutMapping("/api/setting")
    public Result update(@RequestBody UpdatePasswordDto updatePasswordDto) {


        log.info("修改密码: " + updatePasswordDto);
        empService.updatePassword(updatePasswordDto);
        return Result.success();
    }
}
